﻿using System;
using System.Collections.Generic;
using XUtliPoolLib;

// Token: 0x02000002 RID: 2
public class JsonUtil
{
	// Token: 0x06000002 RID: 2 RVA: 0x0000205C File Offset: 0x0000025C
	public static float ParseFloat(object val, float defVal = 0f)
	{
		return (val == null) ? defVal : float.Parse(val.ToString());
	}

	// Token: 0x06000003 RID: 3 RVA: 0x00002080 File Offset: 0x00000280
	public static int ParseInt(object val, int defVal = 0)
	{
		return (val == null) ? defVal : int.Parse(val.ToString());
	}

	// Token: 0x06000004 RID: 4 RVA: 0x000020A4 File Offset: 0x000002A4
	public static bool ParseBool(object val, bool defVal = false)
	{
		bool flag = val == null;
		bool result;
		if (flag)
		{
			result = defVal;
		}
		else
		{
			try
			{
				result = (JsonUtil.ParseInt(val, defVal ? 1 : 0) != 0);
			}
			catch (Exception)
			{
				try
				{
					result = bool.Parse(val.ToString());
				}
				catch (Exception)
				{
					result = defVal;
				}
			}
		}
		return result;
	}

	// Token: 0x06000005 RID: 5 RVA: 0x00002108 File Offset: 0x00000308
	public static DateTime ParseDateTime(object val)
	{
		return DateTime.Parse(val.ToString());
	}

	// Token: 0x06000006 RID: 6 RVA: 0x00002128 File Offset: 0x00000328
	public static string ReadString(IDictionary<string, object> dic, string key, string defVal = "")
	{
		bool flag = dic != null && dic.ContainsKey(key);
		string result;
		if (flag)
		{
			result = ((dic[key] == null) ? defVal : dic[key].ToString());
		}
		else
		{
			result = defVal;
		}
		return result;
	}

	// Token: 0x06000007 RID: 7 RVA: 0x00002168 File Offset: 0x00000368
	public static int ReadInt(IDictionary<string, object> dic, string key, int defVal = 0)
	{
		bool flag = dic != null && dic.ContainsKey(key);
		int result;
		if (flag)
		{
			result = JsonUtil.ParseInt(dic[key], defVal);
		}
		else
		{
			result = defVal;
		}
		return result;
	}

	// Token: 0x06000008 RID: 8 RVA: 0x000021A0 File Offset: 0x000003A0
	public static bool ReadBool(IDictionary<string, object> dic, string key, bool defVal = false)
	{
		bool flag = dic != null && dic.ContainsKey(key);
		bool result;
		if (flag)
		{
			result = JsonUtil.ParseBool(dic[key], defVal);
		}
		else
		{
			result = defVal;
		}
		return result;
	}

	// Token: 0x06000009 RID: 9 RVA: 0x000021D8 File Offset: 0x000003D8
	public static float ReadFloat(IDictionary<string, object> dic, string key, float defVal = 0f)
	{
		bool flag = dic != null && dic.ContainsKey(key);
		float result;
		if (flag)
		{
			result = JsonUtil.ParseFloat(dic[key], defVal);
		}
		else
		{
			result = defVal;
		}
		return result;
	}

	// Token: 0x0600000A RID: 10 RVA: 0x00002210 File Offset: 0x00000410
	public static DateTime ReadDateTime(IDictionary<string, object> dic, string key)
	{
		return JsonUtil.ReadDateTime(dic, key, new DateTime(1, 1, 1, 0, 0, 0));
	}

	// Token: 0x0600000B RID: 11 RVA: 0x00002234 File Offset: 0x00000434
	public static DateTime ReadDateTime(IDictionary<string, object> dic, string key, DateTime defVal)
	{
		bool flag = dic != null && dic.ContainsKey(key);
		if (flag)
		{
			try
			{
				return JsonUtil.ParseDateTime(dic[key]);
			}
			catch (Exception ex)
			{
				XSingleton<XDebug>.singleton.AddErrorLog(ex.Message, null, null, null, null, null);
				return defVal;
			}
		}
		return defVal;
	}

	// Token: 0x0600000C RID: 12 RVA: 0x00002298 File Offset: 0x00000498
	public static string ListToJsonStr(List<string> list)
	{
		bool flag = list == null || list.Count < 1;
		string result;
		if (flag)
		{
			result = "[]";
		}
		else
		{
			bool flag2 = true;
			string text = "[";
			foreach (string str in list)
			{
				bool flag3 = flag2;
				if (flag3)
				{
					flag2 = false;
				}
				else
				{
					text += ",";
				}
				text += str;
			}
			text += "]";
			result = text;
		}
		return result;
	}
}
